home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 163 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.3 KB

  1. Path: fido.asd.sgi.com!austern
  2. From: John Max Skaller <maxtal@suphys.physics.su.oz.au>
  3. Newsgroups: comp.std.c++
  4. Subject: Re: FW: Inherent C++ problem (for comp.std.c++)
  5. Date: 29 Jan 1996 10:54:43 PST
  6. Organization: MAXTAL
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <310CF3E5.313A@suphys.physics.su.oz.au>
  9. References: <01BAE8B0.C408A920@dino.int.com>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: Tue, 30 Jan 1996 02:20:53 +1000
  12. X-Mailer: Mozilla 2.0b6a (WinNT; I)
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMQ0YBUy4NqrwXLNJAQFI6AH+KDqt8q8bJIPJtKGUD+z1iUfiMvmkHpPc
  15.     iEsxOIHrP+AHwEzcnCL/fh1yZBOTpVtx8g+6EHOkaXmi4p6AR8hvAw==
  16.     =BSuf
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. Eugene Lazutkin wrote:
  20. > > And the current wording of the draft allows such optimisations --
  21. > > effectively arbitrary copy constructor invocations can be eliminated if
  22. > > either the copy or the original is never used again (as in this example).
  23. > This is exactly the kind of optimization that one would be expecting but it cannot
  24. > possibly work, at least not with the non-inline copy constructors:
  25. >         class   Complex
  26. >         {
  27. >                 Complex( const Complex& );
  28. >         };
  29. >         int     stupid_global = 0;
  30. >         Complex::Complex( const Complex& c ) : re( c.re ), im( c.im )
  31. >         {
  32. >                 stupid_global++;
  33. >         }
  34. > compiler has no way to know that copy constructor has a non-local side effect.
  35.  
  36.     Completely irrelevent. The compiler is permitted to elide
  37. the copy constructor anyhow. If this changes the observable behaviour
  38. of you program it's your own fault that your code is not deterministic.
  39. If you put a --stupid_global in the destructor, you can assume
  40. after you're done it will be zero. But given a copy operation you 
  41. can't assume it will be incremented by 1: it might be 2 or 0.
  42. (0 is obviously not possible if the two variables are both used).
  43.  
  44. -- 
  45. John Max Skaller               voice: 61-2-566-2189
  46. 81 Glebe Point Rd              fax:   61-2-660-0850
  47. GLEBE NSW 2037                 web: http://www.maxtal.com.au/~skaller/
  48. AUSTRALIA                      email: skaller@maxtal.com.au
  49. ---
  50. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  51.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  52.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  53.